const fs = require('fs');
const path = require('path');

function walk(dir, acc = []) {
  const list = fs.readdirSync(dir);
  list.forEach((f) => {
    const p = path.join(dir, f);
    const stat = fs.statSync(p);
    if (stat.isDirectory()) walk(p, acc);
    else acc.push(p);
  });
  return acc;
}

function checkVars() {
  const files = walk(path.join(__dirname, '..', 'src', 'web', 'components'));
  const misses = [];
  files.filter(f => f.endsWith('.jsx') || f.endsWith('.tsx') || f.endsWith('.css')).forEach((f) => {
    const txt = fs.readFileSync(f, 'utf8');
    const hasVars = /var\(--(bg|text|card|border|muted)\)/.test(txt);
    if (!hasVars) misses.push(f);
  });
  return misses;
}

function checkIcons() {
  const pub = path.join(__dirname, '..', 'public');
  const files = fs.existsSync(pub) ? fs.readdirSync(pub).filter(f => f.endsWith('.svg')) : [];
  const base = new Set(files);
  const lacks = [];
  files.forEach(f => {
    if (!f.endsWith('-dark.svg')) {
      const dark = f.replace(/\.svg$/, '-dark.svg');
      if (!base.has(dark)) lacks.push({ light: f, expectedDark: dark });
    }
  });
  return lacks;
}

function main() {
  const miss = checkVars();
  const iconMiss = checkIcons();
  const report = { componentMissingThemeVars: miss, missingDarkIcons: iconMiss };
  console.log(JSON.stringify(report, null, 2));
}

main();
